#pragma once

#include "table.h"
#include "point.h"

namespace PS
{

template <int Dim>
class Mesh : public Table<Dim, uint32_t>
{
public:
    static_assert(Dim > 0, "Mesh objects need to represent at least one dimension.");

    const int dim = Dim;

    Vector<Dim> _geometric_size;

public:
    Mesh();

    Mesh(const TableIndices<Dim> & sizes);

    void reinit(const TableIndices<Dim> & new_size);

    void render(ImU32 color = IM_COL32(128, 0, 255, 255)) const;

    const Vector<Dim>& geometric_size() const;

}; // namespace PS

}

namespace PS
{

template<int Dim>
Mesh<Dim>::Mesh() : Table<Dim, uint32_t>()
{
}

template<int Dim>
Mesh<Dim>::Mesh(const TableIndices<Dim> & sizes) : Table<Dim>(sizes)
{
}


template<int Dim>
void 
Mesh<Dim>::reinit(const TableIndices<Dim> & new_size)
{
    TableBase<Dim, uint32_t>::reinit(new_size, false);

    for(auto i = 0; i < Dim; ++i)
    {
        _geometric_size[i] = new_size[i];
    }
}

template<int Dim>
const Vector<Dim>& 
Mesh<Dim>::geometric_size() const
{
    return _geometric_size;
}


template <>
void
Mesh<2>::render(ImU32 color) const
{
    // const auto length_x = (double)table_size[0];
    // const auto length_y = (double)table_size[1];

    // double x[8] = {0, length_x, length_x, length_x, length_x, 0, 0, 0};
    // double y[8] = {0, 0, 0, length_y, length_y, length_y, length_y, 0};

    // ImPlot::PlotLine("##Line", x, y, 8);
}

} // namespace PS
